package com.mpc.handler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mpc.adapter.LanguagesAdapter;
import com.mpc.beans.TabResources;
import com.mpc.manager.StaticizeManager;
import com.mpc.manager.UriManager;
import com.mpc.utils.Log;

@WebServlet("")
public class WelcomeRequestHandler extends HttpServlet {
    private static final long serialVersionUID = 1L;
    
    private final String TAG = WelcomeRequestHandler.class.getSimpleName();

    public WelcomeRequestHandler() {
        super();
    }

    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        
        Log.d(TAG, "request uri "+ request.getRequestURI());
        if (UriManager.getInstance().isRequestWelcomePage(request)) {
            String lan = LanguagesAdapter.getLanguagesFromIp(request.getRemoteAddr());
            request.getSession().setAttribute(LanguagesAdapter.LANGUAGES, new TabResources(lan));
            StaticizeManager.getInstance().staticizeRequest(request,
                    response, true);
        }
    }

}
